<template>
  <div>
    <h1 align="center">门店添加</h1>
    <table class="table table-bordered">
      <tr>
        <td align="center">门店名称</td>
        <td>
          <input type="text"  v-model="state.m_name"/>
        </td>
      </tr>
      <tr>
        <td align="center">门店分店名称</td>
        <td>
          <input type="text" v-model="state.m_Fname" />
        </td>
      </tr>
      <tr>
        <td align="center">门店地址</td>
        <td>
          <input type="text"  v-model="state.m_Dizhi"/>
        </td>
      </tr>
      <tr>
        <td align="center">门店照片</td>
        <td>
          <input type="file" />
          <img src="" height="100" width="100" />
        </td>
      </tr>
      <tr>
        <td align="center">电话</td>
        <td>
          <input type="text" v-model="state.m_phone"/>
        </td>
      </tr>
      <tr>
        <td align="center">使用须知</td>
        <td>
          <input type="text" v-model="state.m_desc"/>
        </td>
      </tr>
      <tr>
        <td align="center">备注</td>
        <td>
          <textarea cols="30" rows="3" v-model="state.m_beizhu"></textarea>
        </td>
      </tr>
      <tr>
        <td align="center">信息</td>
        <td>
          <textarea cols="30" rows="3" v-model="state.m_mess"></textarea>
        </td>
      </tr>
      <tr>
        <td align="center" colspan="2">
          <input type="button" value="新增" @click="add" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let data: any = reactive({
  state: {
    m_name: '',
    m_Fname: '',
    m_Dizhi: '',
    m_photot: '',
    m_phone: '',
    m_sate: 1,
    m_desc: '',
    m_beizhu: '',
    m_mess: ''
  }
});
let { state } = toRefs(data);
const add = () => {
  let obj = {
    m_name: state.value.m_name,
    m_Fname: state.value.m_Fname,
    m_Dizhi: state.value.m_Dizhi,
    m_photot: state.value.m_photot,
    m_phone: state.value.m_phone,
    m_sate: state.value.m_sate,
    m_desc: state.value.m_desc,
    m_beizhu: state.value.m_beizhu,
    m_mess: state.value.m_mess
  };
  //验证
  if (state.value.m_name=="") {
    alert("门店不能为空")
    return
  }
  if (state.value.m_Fname=="") {
    alert("分店不能为空")
    return
  }
  axios({
    url: '/api/JIuidan/Add',
    method: 'post',
    data: obj
  })
    .then((res) => {
      console.log(res);
      if (res.data.data == 1) {
        alert('新增成功');
        router.push('/Show');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
